﻿import QtQuick 2.0
import QtQuick.Window 2.12
import QtGraphicalEffects 1.0
import QtQuick.Layouts 1.12
import "../components"

Window {

    id: root

    property var ip;
    property var port;

    // 窗口属性
    modality: Qt.WindowModal
    maximumHeight: 380*dp
    minimumHeight: 380*dp
    maximumWidth: 480*dp
    minimumWidth: 480*dp
    flags: Qt.Window | Qt.FramelessWindowHint
    color: "transparent"


    property int typePage: 0
    signal accept()
    signal reject()

    Rectangle{
        id: rect
        anchors.fill: parent
        radius: 15*dp
        border.color: "#DDDDDD"
        color: "white"

        Column{
            anchors.fill: parent
            anchors.margins: 20*dp
            spacing: 36*dp
            Rectangle{                   // 顶部 =========================================
                height: 40*dp
                width: parent.width
                Row{
                    spacing: 20
                    anchors.fill: parent
                    PushButton{
                        id: button_ip
                        title: "地址修改"
                        underlineSelect: true
                        isSelected: typePage === 0
                        width: 65*dp
                        onReleased: {
                            typePage = 0
                        }
                    }
                    PushButton{
                        id: button_usb
                        title: "外部件维护"
                        underlineSelect: true
                        isSelected: typePage === 1
                        width: 75*dp
                        onReleased: {
                            typePage = 1
                        }
                    }

                }Item{
                    height: 20*dp
                    width: 20*dp
                    x: parent.width-20*dp
                    Text{
                        text: "×"
                        font.pixelSize: 20*dp
                    }
                    MouseArea{
                        anchors.fill: parent
                        cursorShape: Qt.PointingHandCursor
                        onReleased: {
                            console.log("点击关闭")
                            root.close()
                        }
                    }
                }
                CustomBorder{
                    bBorderwidth: 1
                    borderColor: "#CCCCCC"
                }
            }


            Item{                       // IP地址修改 ===========================================
                id: pageRoute
                height: 60*dp
                width: parent.width
                visible: typePage === 0
                property int type: 0
                Column{           // 网络连接
                    id: page_IP
                    height: parent.height
                    width: parent.width
                    spacing: 15*dp

                    Item{
                        height: 40*dp
                        width: 320*dp
                        anchors.horizontalCenter: parent.horizontalCenter

                        LineEditor{
                            title: "通信类型"
                            required: true
                            editWidth: 0
                        }

                        CustomRadio{
                            x: 80*dp
                            title: "网络通信"
                            isChecked: pageRoute.type === 0
                            onReleased: pageRoute.type = 0
                        }
                        CustomRadio{
                            x: 220*dp
                            title: "USB通信"
                            isChecked: pageRoute.type === 1
                            onReleased: pageRoute.type = 1
                        }
                    }

                    LineEditor{
                        id: edit_route
                        title: pageRoute.type===0 ? "IP  地  址" : "串  口  号"
                        anchors.horizontalCenter: parent.horizontalCenter
                        required: true
                        editWidth: 240*dp
                        onTextChanged: {
                            ip=Text
                        }
                    }LineEditor{
                        id: edit_port
                        title: pageRoute.type===0 ? "端  口  号" : "波  特  率"
                        anchors.horizontalCenter: parent.horizontalCenter
                        required: true
                        editWidth: 240*dp
                        onTextChanged: {
                            port=Text
                        }
                    }
                    Item{
                        height: 20*dp
                        width: 20*dp
                    }
                    Item{                       // 确定 / 取消
                        anchors.horizontalCenter: parent.horizontalCenter
                        height: 40*dp
                        width: 320*dp
                        PushButton{
                            x: 30*dp
                            title: "取消"
                            defaultMode2: true
                            onReleased: {
                                root.close()
                            }
                        }PushButton{
                            x: 170*dp
                            title: "确定"
                            defaultMode1: true
                            onReleased: {
                                addDevice()
                                MACO.ckcon(ip,port)
                            }
                        }

                    }
                }
            }

            Item{               // 外部件维护 =================================
                height: 60*dp
                width: parent.width
                visible: typePage === 1
                PushButton{
                    y: 20*dp
                    x: 85*dp
                    title: "水泵开"
                    defaultMode1: true
                    onReleased: {
                        MACO.sbo()
                    }
                }PushButton{
                    y: 20*dp
                    x: 225*dp
                    title: "水泵关"
                    defaultMode2: true
                    onReleased: {
                        MACO.sbc()
                    }
                }PushButton{
                    x: 85*dp
                    y: 85*dp
                    title: "风扇开"
                    defaultMode1: true
                    onReleased: {
                        MACO.fso()
                    }
                }PushButton{
                    x: 225*dp
                    y: 85*dp
                    title: "风扇关"
                    defaultMode2: true
                    onReleased: {
                        MACO.fsc()
                    }
                }PushButton{
                    x: 155*dp
                    y: 199*dp
                    title: "取消"
                    defaultMode2: true
                    onReleased: {
                        root.close()
                    }
                }
            }


        }




    }




}
